home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Scope / Scope Disk #017 (199x)(Scope PD)(US)[WB].zip / Scope Disk #017 (199x)(Scope PD)(US)[WB].adf / DTutor / disktutor < prev    next >
Text File  |  1988-07-04  |  48KB  |  973 lines

  1.  
  2.             An Explanation of AmigaDOS Storage Device Structure
  3.  
  4.   In order for you to use a disk editor to its full disk-saving/disk-altering
  5. potential, you must first understand the structure of an AmigaDOS device.
  6. References will be made to a P.D. disk editor called 'Sectorama', though the
  7. basic information and principals presented in this doc will be applicable to
  8. all disk editors.  Note that to avoid confusion and to provide immediately
  9. applicable info, the block formats presented in this doc are specifically for
  10. 512 byte blocks.  For larger blocks, the size of the Hash Table will vary and
  11. all info after the hash table will be displaced ahead of the hash table so
  12. the secondary-type word is at the end of the block.  All devices I know of to
  13. this point use a 512 byte block.
  14.  
  15.   This document is basically written in two parts.  The first part is an
  16. explanation of what each word in each type of block, how various types
  17. of blocks are structured, and how all these blocks relate to one another on
  18. an AmigaDOS storage device.  The second part is an explanation of how to do
  19. things with a disk editor such as sectorama.
  20.  
  21. I) BLOCK BASICS
  22.    ============
  23.  
  24.   Generally, each block on an AmigaDOS device contains a checksum, a header
  25. key whose value is the disk address of the block, and a block type which tells
  26. you what type of block this is so you know what format that particular block
  27. uses.  Note that when I use the term, 'block', I am referring to a 512 byte
  28. chunk of storage space on an AmigaDOS device.  For example, on a floppy or
  29. hard drive, a block refers to a 512 byte sector.  In VDO: and RAM:, a block
  30. refers to 512 contiguous bytes somewhere in memory.  Also note that the size
  31. of each datum in a block is a 32 bit word.  For all blocks, the first
  32. six words are as follows:
  33.  
  34.      +--------------------+
  35.    0 |    Block Type      |
  36.      +--------------------+
  37.    1 |    Header Key      |
  38.      +--------------------+
  39.    2 |  Number or count   |
  40.      +--------------------+
  41.    3 | Table or Data size |
  42.      +--------------------+
  43.    4 | First or next data |
  44.      +--------------------+
  45.    5 |     Checksum       |
  46.      +--------------------+
  47.      :                    :
  48.  
  49. Block Type  - This identifies the general size and structure of this block.
  50.               It currently has one of three values:
  51.  
  52.               T.SHORT = 00000002  This indicates the block is at the head of
  53.                                   a list (i.e. a HEADER BLOCK).
  54.  
  55.               T.LIST  = 00000010  This indicates the block is a LIST BLOCK.
  56.                                   A list block is a member of a linked list
  57.                                   list blocks and contains a table of pointers
  58.                                   to data blocks.
  59.  
  60.               T.DATA  = 00000008  This indicates the block is a DATA BLOCK.
  61.                                   A data block is simply a block that contains
  62.                                   data and will be described later in this
  63.                                   doc.
  64.  
  65. Header Key  - This 32-bit word is the device's address for this block.  It
  66.               is a pointer to this block.
  67.  
  68. Number or Count - If this not a data block, this is a total count of data
  69.                   blocks (and, hence, the highest sequence number of any
  70.                   data block) pointed-to by this block.
  71.  
  72.                 - If this block is a data block, this number is the sequence
  73.                   number of this data block.  That is, it tells us this data
  74.                   block is the n'th member of a list of data blocks.
  75.  
  76. Table or Data Size - This is a count of how many 32-bit words there are in
  77.                      the table or data starting at word # 6 in this block.
  78.  
  79. First or Next Data - This is a pointer to the data block following this block.
  80.                      If this block is a header or a list block, then this
  81.                      pointer will point to the first data block in a list
  82.                      of data blocks.
  83.  
  84. Checksum - When this number and the values of all other words in this block
  85.            are added up, the sum must be zero.  This is how bad blocks are
  86.            detected by AmigaDOS.
  87.  
  88. For all types of blocks excepting data blocks, the last four words have the
  89. following format:
  90.  
  91.      :                :
  92.      +----------------+
  93.   7C |   Hashchain    |
  94.      +----------------+
  95.   7D |    Parent      |
  96.      +----------------+
  97.   7E |   Extension    |
  98.      +----------------+
  99.   7F | Secondary Type |
  100.      +----------------+
  101.  
  102. Hashchain - points to the next entry on this hash chain.
  103.  
  104. Parent - pointer to the parent directory.  The parent directory is the
  105.          directory block which either points to this block or points to a
  106.          linked list (i.e. hash chain) of which this block is a member.
  107.  
  108. Extension - pointer to the next extension block which essentially extends the
  109.             table which starts at word # 6 of this block.
  110.  
  111. Secondary Type - This exactly identifies what kind of block this is.  This
  112.                  tells us exactly what function and structure this block has.
  113.                  The possible codes in this word are:
  114.  
  115.                  ST.ROOT    = 00000001  This identifies the ROOT BLOCK, which
  116.                                         is the device's 'root directory'.
  117.                                         This block ultimately points to all
  118.                                         the files and directories on the
  119.                                         storage device.
  120.  
  121.                  ST.USERDIR = 00000002  This identifies a USER DIRECTORY BLOCK
  122.                                         which points to all the files and
  123.                                         directories which have been defined
  124.                                         for this directory.
  125.  
  126.                  ST.FILE    = FFFFFFFD  This identifies either a FILE HEADER
  127.                                         BLOCK, if the block type at word # 1
  128.                                         is T.SHORT, or a FILE LIST BLOCK if
  129.                                         the block type is T.LIST.
  130.                                         A FILE HEADER BLOCK points to all the
  131.                                         data blocks that make up the file.  If
  132.                                         there are too many data blocks to be
  133.                                         pointed to by this block, a list of
  134.                                         FILE LIST BLOCKS is pointed-to by the
  135.                                         extension pointer at word # 7E.  A
  136.                                         FILE LIST BLOCK simply extends the
  137.                                         table and points to the next FILE LIST
  138.                                         BLOCK if more data block pointers are
  139.                                         required.
  140.  
  141. Note that the above-mentioned word definitions are not applicable to some
  142. block types and functions.  Where their function is non-applicable, their
  143. value is usually set at zero.
  144.  
  145. II) THE ROOT BLOCK
  146.     ==============
  147.  
  148.   The block that ultimately points to everything on the disk is called the
  149. 'Root Block'.  This block usually resides in the exact center of a storage
  150. device to minimize the distance a read/write head of a floppy or hard disk
  151. must move when travelling from an outer cylinder to the Root Block.  The
  152. format of the Root Block is as follows:
  153.  
  154.         symbolic    usual
  155.          value      value
  156.      +----------------------+
  157.    0 |  T.SHORT  = 00000002 |  Indicates this is a 512 byte header block
  158.      +----------------------+
  159.    1 |        0  = 00000000 |  Header Key (Always zero in a root block)
  160.      +----------------------+
  161.    2 |        0  = 00000000 |  Highest sequence number in chain (0 for root)
  162.      +----------------------+
  163.    3 |  HT SIZE  = 00000048 |  Hashtable size (=blocksize-56 = 512/4-56 words)
  164.      +----------------------+
  165.    4 |        0  = 00000000 |
  166.      +----------------------+
  167.    5 | CHECKSUM  =    ?     |  Checksum for this block
  168.  ----+----------------------+
  169. {  6 |                      |
  170. {    |      Hash Table      |
  171. { to :                      :
  172. {    :                      :
  173. { 4D |                      |
  174.  ----+----------------------+
  175.   4E |   BMFLAG  = FFFFFFFF |  True (all F's) if device or disk bitmap valid
  176.  ----+----------------------+
  177. { 4F |                      |
  178. {    |     Bitmap Pages     |
  179. { to :                      :
  180. {    :                      :
  181. { 68 |                      |
  182.  ----+----------------------+
  183.   69 |     DAYS  =    ?     |  Volume last altered date and time.
  184.      +----------------------+  Date is in packed format.
  185.   6A |     MINS  =    ?     |  Time is rated in minutes and ticks.
  186.      +----------------------+  One tick is 1/60th of a second.
  187.   6B |    TICKS  =    ?     |
  188.  ----+----------------------+
  189. { 6C |                      |  Volume name as a BCPL string of 30 characters
  190. {    |      Disk Name       |  or less, though the amount of space to store
  191. { to :                      :  this string always remains the same size.
  192. {    :                      :
  193. { 78 |                      |
  194.  ----+----------------------+
  195.   79 |CREATEDAYS =    ?     |  Date and time when this volume was created.
  196.      +----------------------+  Format here, as well as all date/time data
  197.   7A |CREATEMINS =    ?     |  presented in other types of blocks are in the
  198.      +----------------------+  format shown for the above volume last altered
  199.   7B |CREATETICKS=    ?     |  date and time.
  200.      +----------------------+
  201.   7C |        0  = 00000000 |  Next entry on this hash chain (0 for root)
  202.      +----------------------+
  203.   7D |        0  = 00000000 |  Parent directory (always 0 for root)
  204.      +----------------------+
  205.   7E |        0  = 00000000 |  Extension  (always 0 for root)
  206.      +----------------------+
  207.   7F |  ST.ROOT  = 00000001 |  Secondary type indicates this is a Root Block
  208.      +----------------------+
  209.  
  210. -> What the heck is a HASH TABLE?
  211.  
  212.   A HASH TABLE is a table of pointers to files and to lists of files.  To
  213. locate a particular file in the table, the name of the file is used to
  214. calculate where in the table it is to be located.  This location may not be
  215. unique to the name of this file.  In this case, the pointer will point to a
  216. linked list of file headers which must be traversed until the file header for
  217. the file we're searching for is found.  This linked list is referred to as a
  218. HASH CHAIN.
  219.  
  220.   The actual searching-out of files will be discussed in more practical terms
  221. in the practical portion of this document.
  222.  
  223. -> What things are pointed-to by pointers in a HASH TABLE?
  224.  
  225.   Each non-zero pointers in the hash table points to either a FILE HEADER
  226. BLOCK or a USER DIRECTORY BLOCK which, in turn, may have a hash chain pointer
  227. which will point to the next file header block or user directory block in
  228. the hash chain.
  229.  
  230. -> What are bitmap pages?
  231.  
  232.   The words in the list of bitmap pages point to 512 byte blocks which
  233. simply map-out which blocks on the device are used, and which are free for
  234. usage.  I don't yet understand how the bitmaps are set-up or maintained,
  235. but as soon as I find out, I'll slip the info into this document.
  236.  
  237. -> What is a BCPL string?
  238.  
  239.   This is a string of bytes where the first byte indicates the number of
  240. characters in the string (say, 'n' characters), the next 'n' characters
  241. contain the ASCII values for the string, and the rest of the string is
  242. ignored.  For example, on my Workbench disk, a hex dump of the string looks
  243. like this:
  244.  
  245. 09576F72 6B62656E 63686F72 6B62656E .Workbenchorkben
  246. 63680000 00000000 00000000 00000000 ch..............
  247. 00000000 00000000                   ........
  248.  
  249. Where the 09 at the beginning specifies that only the next nine characters
  250. are valid characters of the string and the rest are ignored.
  251.  
  252. Note that for the root block, zeros are always in the Header Key, Sequence
  253. Number, Hash cain, Parent, and Extension fields.  This is because a ROOT BLOCK
  254. is always at a specific spot on the device (for a disk, it is exactly
  255. cenetered between the outer- and inner-most cylinders), it never require hash
  256. table extensions, it is not pointed-to by a hash table and is not part of a
  257. hash list, and it does not have a parent directory.
  258.  
  259. III) USER DIRECTORY BLOCKS
  260.      =====================
  261.  
  262.   A user directory block is created when a new directory is made in a storage
  263. device.  It contains its own name and protection status, its parent directory,
  264. as well as a hash table pointing to files and user directories that have been
  265. placed into this directory.  The hash table functions exactly the same way as
  266. that in the ROOT BLOCK.  The format of a USER DIRECTORY BLOCK is as follows:
  267.  
  268.         symbolic    usual
  269.          value      value
  270.      +----------------------+
  271.    0 |  T.SHORT  = 00000002 |  Indicates this is a 512 byte header block
  272.      +----------------------+
  273.    1 |  OWN KEY  =    ?     |  Header Key (pointer to this very block)
  274.      +----------------------+
  275.    2 |        0  = 00000000 |  Highest sequence number in chain (always zero)
  276.      +----------------------+
  277.    3 |        0  = 00000000 |
  278.      +----------------------+
  279.    4 |        0  = 00000000 |
  280.      +----------------------+
  281.    5 | CHECKSUM  =    ?     |  Checksum for this block
  282.  ----+----------------------+
  283. {  6 |                      |
  284. {    |      Hash Table      |
  285. { to :                      :
  286. {    :                      :
  287. { 4D |                      |
  288.  ----+----------------------+
  289.   4E |    SPARE  = 00000000 |
  290.   4F |    SPARE  = 00000000 |
  291.      +----------------------+
  292.   50 |  PROTECT  =    ?     |  Protection bits (Read/Write/Execute/Delete)
  293.      +----------------------+
  294.   51 |        0  = 00000000 |  Unused (always zero)
  295.  ----+----------------------+
  296. { 52 |                      |
  297. {    |       COMMENT        |  Stored as a BCPL string
  298. { to :                      :  (up to 90 characters)
  299. {    :                      :
  300. { 68 |                      |
  301.  ----+----------------------+
  302.   69 |     DAYS  =    ?     |  Directory creation date and time.
  303.      +----------------------+
  304.   6A |     MINS  =    ?     |
  305.      +----------------------+
  306.   6B |    TICKS  =    ?     |
  307.  ----+----------------------+
  308. { 6C |                      |
  309. {    |    Directory Name    |  Directory name as a BCPL
  310. { to :                      :  (up to 30 characters)
  311. {    :                      :
  312. { 7B |                      |
  313.  ----+----------------------+
  314.   7C |HASHCHAIN  =    ?     |  Next entry with same hash value
  315.      +----------------------+
  316.   7D |   PARENT  =    ?     |  Back pointer to parent directory
  317.      +----------------------+
  318.   7E |        0  = 00000000 |  Extension  (always 0 for root)
  319.      +----------------------+
  320.   7F |  ST.ROOT  = 00000002 |  Secondary type indicates this is a Root Block
  321.      +----------------------+
  322.  
  323. IV) FILE HEADER BLOCK
  324.     =================
  325.  
  326.   This block is the first block of any given file.  It contains file
  327. information such as the name, size, protection status, creation date, and a
  328. pointer to the parent directory block of the file.  It also contains a table
  329. of pointers to all the data blocks that make up the file.  If there are more
  330. data blocks than there are pointers in the table of data block pointers (at
  331. words # 6 to 4D), an extension pointer is provided to a FILE LIST BLOCK which
  332. contains a similar table of data block pointers.  If the file list block
  333. still doesn't provide enough pointers, it will provide yet another extension
  334. pointer to another FILE LIST BLOCK.  This list of FILE LIST BLOCKS extends
  335. until enough pointers are provided to point to all the data blocks of the
  336. file.
  337.  
  338.         symbolic    usual
  339.          value      value
  340.      +----------------------+
  341.    0 |  T.SHORT  = 00000002 |  Indicates this is a 512 byte header block
  342.      +----------------------+
  343.    1 |  OWN KEY  =    ?     |  Header Key (pointer to this very block)
  344.      +----------------------+
  345.    2 |HIGHEST SEQ=    ?     |  Number of data blocks pointed-to by this block
  346.      +----------------------+
  347.    3 |DATA SIZE  =    ?     |
  348.      +----------------------+
  349.    4 |FIRST DATA =    ?     |  Pointer to the first data block of the file
  350.      +----------------------+
  351.    5 | CHECKSUM  =    ?     |  Checksum for this block
  352.  ----+----------------------+
  353. {  6 |          :           |
  354. {    :          :           :  List of pointers to data blocks
  355. { to :          :           :  (i.e. Data block keys)
  356. {    |     DATA BLOCK 3     |
  357. {    |     DATA BLOCK 2     |
  358. { 4D |     DATA BLOCK 1     |
  359.  ----+----------------------+
  360.   4E |    SPARE  = 00000000 |
  361.   4F |    SPARE  = 00000000 |
  362.      +----------------------+
  363.   50 |  PROTECT  =    ?     |  Protection bits (Read/Write/Execute/Delete)
  364.      +----------------------+
  365.   51 | BYTESIZE  =    ?     |  Total size of file in bytes
  366.  ----+----------------------+
  367. { 52 |                      |
  368. {    |       COMMENT        |  Stored as a BCPL string
  369. { to :                      :  (up to 90 characters)
  370. {    :                      :
  371. { 68 |                      |
  372.  ----+----------------------+
  373.   69 |     DAYS  =    ?     |  File creation date and time.
  374.      +----------------------+
  375.   6A |     MINS  =    ?     |
  376.      +----------------------+
  377.   6B |    TICKS  =    ?     |
  378.  ----+----------------------+
  379. { 6C |                      |
  380. {    |      File Name       |  File  name as a BCPL string
  381. { to :                      :  (up to 30 characters)
  382. {    :                      :
  383. { 7B |                      |
  384.  ----+----------------------+
  385.   7C |HASHCHAIN  =    ?     |  Next entry with same hash value
  386.      +----------------------+
  387.   7D |   PARENT  =    ?     |  Back pointer to parent directory
  388.      +----------------------+
  389.   7E |EXTENSION  =    ?     |  Pointer to a FILE LIST BLOCK (if required)
  390.      +----------------------+
  391.   7F |  ST.ROOT  = FFFFFFFD |  Secondary type indicates this is a Root Block
  392.      +----------------------+
  393.  
  394. V) FILE LIST BLOCK
  395.    ===============
  396.  
  397.   This type of block is used to extend the table of data block keys
  398. (pointers) of a FILE HEADER BLOCK when the table in the FILE HEADER BLOCK
  399. hasn't enough pointers to point to all the file's data blocks.  If a FILE
  400. LIST BLOCK doesn't have enough pointers to point to the rest of the file's
  401. data blocks, the EXTENSION pointer of the block will point to yet another
  402. FILE LIST BLOCK.  The extension list continues until enough pointers are
  403. provided for all the data blocks in the file.
  404.  
  405.         symbolic    usual
  406.          value      value
  407.      +----------------------+
  408.    0 |  T.LIST   = 00000010 |  Indicates this is a file list block
  409.      +----------------------+
  410.    1 |  OWN KEY  =    ?     |  Header Key (pointer to this very block)
  411.      +----------------------+
  412.    2 |BLOCK COUNT=    ?     |  Number of data blocks pointed-to by this block
  413.      +----------------------+
  414.    3 |DATA SIZE  = 00000000 |
  415.      +----------------------+
  416.    4 |FIRST DATA =    ?     |  Pointer to the first data block of the file
  417.      +----------------------+
  418.    5 | CHECKSUM  =    ?     |  Checksum for this block
  419.  ----+----------------------+
  420. {  6 |          :           |
  421. {    :          :           :  Extended list of pointers to data blocks
  422. { to :          :           :  (i.e. Data block keys)
  423. {    |     DATA BLOCK 3     |
  424. {    |     DATA BLOCK 2     |
  425. { 4D |     DATA BLOCK 1     |
  426.  ----+----------------------+
  427. { 4E |                      |
  428. {    |        unused        |  unused (all zeros)
  429. { to :                      :
  430. {    :                      :
  431. { 7B |                      |
  432.  ----+----------------------+
  433.   7C |        0  = 00000000 |  Next in hash list (always zero for list block)
  434.      +----------------------+
  435.   7D |   PARENT  =    ?     |  Points to the file header block of this file
  436.      +----------------------+
  437.   7E |EXTENSION  =    ?     |  Points to the next FILE LIST BLOCK (if required)
  438.      +----------------------+
  439.   7F |  ST.ROOT  = FFFFFFFD |  Secondary type indicates this is a Root Block
  440.      +----------------------+
  441.  
  442. VI)  DATA BLOCK
  443.      ==========
  444.  
  445.   A data block contains data from a file and is pointed-to by preceding
  446. data blocks and by a pointer in a table in either a FILE HEADER BLOCK or a
  447. FILE LIST BLOCK.  Thus, the data block can be accessed directly from a header
  448. or list block of a file, or sequentially by following the linked list of data
  449. blocks.  Each data block also points to the FILE HEADER BLOCK which describes
  450. the file which contains this data block.  A sequence number is also present
  451. in a data block, and indicates that this data block is the n'th data block
  452. in the list of the file's data blocks.
  453.  
  454.         symbolic    usual
  455.          value      value
  456.      +----------------------+
  457.    0 |  T.DATA   = 00000008 |  Indicates this is a data block
  458.      +----------------------+
  459.    1 |  HEADER   =    ?     |  Header key pointing to the file header block.
  460.      +----------------------+
  461.    2 |  SEQ NUM  =    ?     |  Sequence number
  462.      +----------------------+
  463.    3 | DATA SIZE = 00000000 |  Number of words of data in this block
  464.      +----------------------+
  465.    4 | NEXT DATA =    ?     |  Pointer to the next data block
  466.      +----------------------+
  467.    5 | CHECKSUM  =    ?     |  Checksum for this block
  468.  ----+----------------------+
  469. {  6 |                      |
  470. {    |         DATA         |
  471. { to :                      :
  472. {    :                      :
  473. { 7F |                      |
  474.      +----------------------+
  475.  
  476. VII)  HOW DO THE BLOCKS FIT TOGETHER?
  477.       ===============================
  478.  
  479.   The ROOT BLOCK is located at a fixed location, exactly between the highest
  480. and lowest addresses available on a storage device.  The ROOT BLOCK contains
  481. a table of pointers (the hash table) to linked lists (hash chains) of USER
  482. DIRECTORY BLOCKS and FILE HEADER BLOCKS which describe user directories and
  483. files accessible from the root directory.
  484.  
  485.   A USER DIRECTORY BLOCK contains the name and protection status of a user
  486. directory, as well as a hash table containing pointers to hash chains of
  487. USER DIRECTORY BLOCKS and FILE HEADER BLOCKS which describe user directories
  488. and files accessible from that user directory.  Since the USER DIRECTORY
  489. itself is a member of a hash chain, it also contains pointers to its parent
  490. directory block and to the next USER DIRECTORY BLOCK or FILE HEADER BLOCK in
  491. the header chain.
  492.  
  493.   A FILE HEADER BLOCK contains information describing the file it represents,
  494. as well as a table of pointers to DATA BLOCKS that make up the file.  If
  495. there aren't enough pointers in this table to point to all the file's DATA
  496. BLOCKS, an EXTENSION pointer points to a list of FILE LIST BLOCKS which
  497. extend the table.  Since the FILE HEADER BLOCK is a member of a hash chain,
  498. it contains pointers to its parent directory and to the next USER DIRECTORY
  499. BLOCK or FILE HEADER BLOCK in the header chain.
  500.  
  501.   A FILE LIST BLOCK contains a table of pointers to DATA BLOCKS and extends
  502. the table of the FILE HEADER BLOCK or FILE LIST BLOCK which points to this
  503. FILE LIST BLOCK.  If there aren't enough pointers in this table to point to
  504. the remainder of the file's DATA BLOCKS, an EXTENSION pointer in the FILE
  505. LIST BLOCK points to the next FILE LIST BLOCK to extend its data block table.
  506.  
  507.   A DATA BLOCK's main content is data.  It is part of a linked list of DATA
  508. BLOCKS and includes a pointer to the next DATA BLOCK in the list.  It also
  509. includes a sequence number indicating that this DATA BLOCK is the n'th DATA
  510. BLOCK in the list.  Each DATA BLOCK is pointed-to both by the preceding DATA
  511. BLOCK in the list, and by a pointer in a data block table in either a FILE
  512. HEADER BLOCK or a FILE LIST BLOCK.  Each DATA BLOCK also contains a pointer
  513. to the FILE HEADER BLOCK which describes the file which the DATA BLOCK is a
  514. member of.
  515.  
  516.   Confused?  Don't worry, practical stuff is coming up next...
  517.  
  518. VIII) UNDERSTANDING YOUR DISK EDITOR
  519.       ==============================
  520.  
  521.   Before we begin playing with a disk editor, I recommend that you create a
  522. backup of a densely populated disk, like your workbench, so that if a wrong
  523. key is pressed while looking through the backup, you haven't done damage to
  524. your one and only copy.
  525.  
  526. a) A Look at Sectorama
  527.    ===================
  528.      For those of you lucky enough to have a copy of sectorama handy, fire it
  529.    up and I can explain what all those obscure thingies on the right side and
  530.    of the top line of the screen mean and where, from the block you are
  531.    looking at, the information was taken.
  532.  
  533.      The lower right hand portion of the display identifies the storage
  534.    device currently being examined by this sectorama display.  It gives us
  535.    the device name (as a volume name), the device unit number, and the
  536.    filename of the device driver that communicates with the device.
  537.  
  538.      The display section immediately above this info contains hardware-
  539.    dependant information.  The middle column shows us the the sector, track
  540.    cylinder, surface, and block numbers of the block currently being
  541.    displayed.  This information is all given in decimal values.  All these
  542.    statistics are all determined by a set of info used by the device
  543.    driver.  For a floppy, for example, it these tell us on which cylinder the
  544.    read/write head is currently positioned over, which sector on which
  545.    surface (top or bottom) is being read by the read/write head, and the
  546.    hardware-specific track and block numbers for that sector.  The rightmost
  547.    column are device statistics.  These tell us how many of each category
  548.    there are on this device.
  549.  
  550.      Note that by pointing at any of the figures in the center column of this
  551.    section, you can change the current values.  By changing sector, surface,
  552.    or block number, you can examine any sector of the device immediately.
  553.  
  554.      The section immediately above the hardware information contains
  555.    information about (and from) the block currently being displayed:
  556.  
  557.      Date       -refers to the creation date which is taken from word # 69.
  558.  
  559.      Time       -is calculated from words # 6A (to get hours and minutes) and
  560.                  # 6B (to get seconds).
  561.  
  562.      Highest Seq # -is taken from word # 2 and refers to the number of
  563.                          words used in the table starting at word # 6.
  564.  
  565.      Data Size  -refers to the size of the table at word # 6.
  566.  
  567.      Protect    -refers to the protection status of a user directory block or
  568.                  a file header block and is taken from the value at word # 50
  569.  
  570.      File Bytes -refers to the size of a file in kilobytes.  This value is
  571.                  1/1000'th the value of word # 51.
  572.  
  573.      The section at the upper right corner of the display is a list of
  574.    keyboard commands with current values beside them.  All except the
  575.    checksum are pointers to other blocks in the device.  The checksum is the
  576.    current block's checksum value taken from word # 5.  This value must be
  577.    recalculated every time you make an alteration to a block.  The pointers
  578.    shown beside each command are as follows:
  579.  
  580.      R-Go Root     -points to the root directory of this disk.  This pointer
  581.                     is a constant value which has been calculate for this
  582.                     storage device.
  583.  
  584.      P-Go Parent   -points to a FILE HEADER BLOCK's or USER DIRECTORY BLOCK's
  585.                     parent directory block.  This pointer is taken from
  586.                     word # 7D.
  587.  
  588.      C-Go Hash Chain -points to the next FILE HEADER BLOCK or USER
  589.                       DIRECTORY BLOCK in this blocks hash chain.  This
  590.                       pointer is taken from word # 7C.
  591.  
  592.      X-Go Extension -points to the next FILE LIST BLOCK in an extension
  593.                      chain.  This pointer is taken from word # 7E.
  594.  
  595.      H-Go Header    -for DATA BLOCKS, this points to the FILE HEADER BLOCK
  596.                      to which this DATA BLOCK belongs.
  597.                     -for other blocks, this points to the block currently
  598.                      being examined.
  599.                     -in both cases, this pointer is taken from word # 1.
  600.  
  601.      For all the above commands, if you type the letter to initiate the
  602.    command, sectorama will jump to the block corresponding to the pointer
  603.    displayed beside the command.
  604.  
  605.      At the top of the display are three more information displays.  On the
  606.    left is the block number of the block currently being displayed.  Next to
  607.    that is the Type of the block being displayed.  The block type is
  608.    determined by word # 0, which contains the block type, and word # 7F,
  609.    which contains the secondary type.
  610.  
  611.      Next to the block type is the Name of the block.  This name may be a
  612.    volume name or a directory name or a file name, depending on if this block
  613.    is a ROOT BLOCK, a USER DIRECTORY BLOCK, or a FILE HEADER BLOCK,
  614.    respectively.
  615.  
  616. b) Sectorama commands
  617.    ==================
  618.      All the sectorama commands are adequately described in the documentation
  619.    file that accompanies it.
  620.  
  621. c) A Practical Session
  622.    ===================
  623.    i) Touring a floppy, a summary
  624.       ---------------------------
  625.          I suggest that as you progress through this little step-by-step
  626.       blathering that each time you come across a new type of block, you
  627.       compare the data being displayed by sectorama to the block
  628.       descriptions shown above so that you become more familiar about where
  629.       things are located in each type of block.
  630.  
  631.          The steps for performing the operations summarized below with
  632.       Sectorama are described in detail, with a running commentary, in
  633.       section ii) Touring a floppy with Sectorama.  For following these
  634.       steps with any other disk editor, I suggest that you quickly read
  635.       through the Sectorama tour to familiarize yourself with what is
  636.       being attempted, then attempt the summarized steps below to familiarize
  637.       yourself with your disk editor and AmigaDOS.
  638.  
  639.          Steps 1 thru 8 will guide you from a disk's ROOT BLOCK, into a file
  640.       and through all the data blocks in that file.  A quick summary of
  641.       these steps is as follows:
  642.  
  643.          Steps 9 thru 14 show you how to alter a block and write it to disk.
  644.  
  645.      _A step-by-step of the tour, in summary is as follows:
  646.  
  647.     / 1. Run the disk editor.
  648.     |
  649.     | 1a.  (Load the root block.  This is done automatically by Sectorama.)
  650.     |
  651.     | 2. Locate the 'c' directory by using the hash function.
  652. Part< 3. Load the USER DIRECTORY BLOCK for the c directory.
  653.  1a | 4. Locate the 'dir' command file by using the hash function.
  654.     | 5. Load the FILE HEADER BLOCK for the 'dir' file.
  655.     | 6. Load the first DATA BLOCK of the 'dir' file.
  656.     | 7. Load and examine each consecutive DATA BLOCK of the 'dir' file until
  657.     |      the last DATA BLOCK in the file has been loaded and examined.
  658.     \_8. Load the FILE HEADER BLOCK pointed-to by the final DATA BLOCK.
  659.      _
  660.     / 9.  Locate and select the first word in the comment filed of the FILE
  661.     |       HEADER BLOCK for the 'dir' file.
  662.     | 10. Edit the ASCII values of the comment field.
  663. Part< 11. Edit the hexadecimal value of the first byte of the first word of
  664.  1b |       the comment field to insert the string length of the comment
  665.     |       created in step 10.
  666.     | 12. Re-calculate the checksum for this block.
  667.     | 13. Write the altered block to disk.
  668.     \_14. Quit the disk editor.
  669.  
  670.   ii) Touring a floppy with Sectorama...
  671.       ----------------------------------
  672.  
  673.       1.   O.K., get your disk editor up and running (if it isn't already)
  674.          and begin examining a back-up copy of your workbench disk.  For
  675.          sectorama, the CLI command line for this if the disk was in df0:
  676.          would look like:
  677.  
  678.          1> run sec df0:
  679.  
  680.          What you will see on your display (in neato-keen hi-res) is data
  681.       of the ROOT BLOCK of df0:.  On top of the display is 'Type=ROOT DIR'
  682.       which indicates that the block currently being displayed is a
  683.       ROOT BLOCK.
  684.  
  685.       2.  Now that we are at the ROOT BLOCK, lets find the c directory.  The
  686.       first step for this is to find out what value we get when we use the
  687.       hash function on the string 'c'.  To do this you must envoke the hash
  688.       function by picking 'COMPUTE HASH VALUE' under the SEARCH menu, then
  689.       typing the file or directory name, in this case the letter c followed
  690.       by a <RETURN>.  This highlights the block address of the hash chain
  691.       which contains the c directory.
  692.  
  693.       3.  Now that you've found the possible whereabouts of the c directory
  694.       jump to it by hitting the j key.  If (more likely than not) on top of
  695.       the display is 'Name=c' then the display is currently displaying the
  696.       contents of the c directory and the top of the display has
  697.       'Type=DIRECTORY' indicating that what is being displayed is a USER
  698.       DIRECTORY BLOCK, which is essentially the c directory of df0:.
  699.  
  700.       4.  Now that we're at the c directory, let's look at a file containing
  701.       loadable/executable code for a well-known function... say, the file
  702.       called 'dir'.  Envoke the hash function as before using the string
  703.       dir.  The block address of the hash chain that contains the dir file
  704.       will be highlighted.
  705.  
  706.       5.  Press the j key to jump to the beginning of the hash chain which
  707.       will have (again, more likely than not) 'Type=FILE   Name=dir'
  708.       displayed above the table of block data.  The Type=FILE indicates that
  709.       this is the header block for the file indicated by Name=dir.  This is a
  710.       fairly short file, so that all the block addresses for the DATA BLOCKS
  711.       for this file are included in this block and that no extension blocks
  712.       are required for this file, which is why the block address beside
  713.       'X-Go Extension=' is 00000000.
  714.  
  715.         Also notice that the block address beside 'D-Go Next Data' is the
  716.       same as the last entry in the data table of this block (at word # 4D
  717.       according to my version of dir).  This is because data blocks are
  718.       arranged in this table starting at the end of the table and working
  719.       towards the beginning.
  720.  
  721.       6.  Let's take a look at the first DATA BLOCK, then, by hitting the
  722.       d key to 'Go Next Data'.  What will be displayed is the first DATA
  723.       BLOCK of the dir file.  On top of the display will be 'Type=DATA BLOCK'
  724.       confirming that fact.  Note that word # 04, which has the same value as
  725.       is displayed beside D-Go Next Data =, points to the next DATA BLOCK for
  726.       this file.
  727.  
  728.       7.  Let's traverse the entire list of DATA BLOCKS to see what the last
  729.       one in the list looks like.  You can do this by hitting the D key
  730.       about 16 times or so.  While you do this, note that the value beside
  731.       H-Go Header =  stays constant for each data block while all the other
  732.       values remain constant.  The value beside H-Go Header =  points to
  733.       the FILE HEADER BLOCK which owns the DATA BLOCK.  If this ever changes
  734.       as you are traversing a list of DATA BLOCKS, you KNOW there is a
  735.       problem with the file.  Also note that as you jump from block to block,
  736.       the HISTORY list at the bottom of the display keeps track of your last
  737.       eight jumps.  This is a valuable feature when you overshoot a problem
  738.       area and need to know where you've been in previous jumps.  Also note
  739.       that for each successive DATA BLOCK that you display, the sequence
  740.       number displayed in the middle of the right part of the screen is
  741.       incremented by one.  This helps you figure out exactly where you are in
  742.       the file you are looking through.  If ever this sequence number jumps
  743.       up or down by more that one, you know the DATA BLOCK is out of its
  744.       proper sequence.
  745.  
  746.       8.  Once you've reach the end of the DATA BLOCK list, you will find that
  747.       hitting the D key will now only cause the display to flash, indicating
  748.       that this is indeed the end of the DATA BLOCK list for this file.  Lets
  749.       jump back to the FILE HEADER BLOCK for the 'dir' file by hitting the
  750.       h key (for H-Go Header).
  751.  
  752.       9.  Now that we've jumped around the disk doing some block reading,
  753.       let's get more adventurous.  Let's modify a block on the disk.  By
  754.       comparing the FILE HEADER BLOCK description above, we note that the
  755.       comment field in this block begins at word # 52 and ends at word # 68.
  756.       Move your pointer to word # 52 and click your left mouse button to
  757.       highlight it.
  758.  
  759.       10. Next, press the A key to enter ASCII edit mode (the command list on
  760.       the right of the display describes it as Edir ASCII).  Now type a space
  761.       and then some sort of short comment, being careful not to type past
  762.       word #68.  For example, I typed the comment ' dir, oh dir' beginning
  763.       in word #52.  Note that the delete key and backspace key do not work
  764.       normally in this mode, and actually produce their own special ascii
  765.       values.  To re-type something, you must either move your pointer to the
  766.       desired location and click, or use your cursor keys to move the
  767.       highlighter to the desired character, then type your correction.
  768.       To exit this edit mode, simply hit <RETURN>.
  769.  
  770.       11. To make our comment a proper BCPL string, we must put a character
  771.       count at word # 52.  Count how many characters there are in your string
  772.       and convert this number to hexadecimal.  Next, enter the hexadecimal
  773.       edit mode by hitting the e key (for Edit), type your two-digit
  774.       hexadecimal value and hit return.  For example, in my 'dir, oh dir'
  775.       comment there are eleven characters.  Eleven converts to 0B in
  776.       hexadecimal, so I edit word #52, type 0B, and hit return.
  777.  
  778.       12. Since we've altered the contents of this block, the checksum for
  779.       this block is no longer valid.  We must hit the k key to calculate a
  780.       new checksum.  When you have done this, you will note that the value
  781.       beside K-Checksum = and at word # 05 have changed to the newly
  782.       calculated checksum.
  783.  
  784.       13.  Note that any changes you have made so far haven't been written to
  785.       disk at all.  Nothing is ever written to disk until you actually write
  786.       it by hitting the u key to 'Update block'.  To incorporate your new
  787.       file comment for the file called 'dir', hit the u key.
  788.  
  789.       14.  Then quit Sectorama, and list df0:c/dir to see the
  790.       change that you've just made.  Note that you may have to list the whole
  791.       c directory to see the change since AmigaDOS keeps track of which
  792.       sectors of which device it currently has in buffers, and will avoid
  793.       fetching your modified sector if it is currently in df0:'s buffer.
  794.  
  795.         What we've just done is to examine a disk, seek-out a specific file,
  796.       look through the file's data, then modify the FILE HEADER BLOCK of
  797.       that file.  What we haven't seen yet are two important data
  798.       structures which we will look for now.  Specifically, these structures
  799.       are the hash chain, and the file list.
  800.  
  801.       1. to 3.  Same as steps 1. to 3. above. (Locate & load the c directory)
  802.  
  803.       4. Now calculate the hash value for Echo using the Calculate Hash Value
  804.       function.  Write the highlighted number down.
  805.  
  806.       5. Calculate the hash value for Quit using the same hash function used
  807.       in step 4.
  808.  
  809.       6. Calculate the hash value for Why using the hash function.  You will
  810.       find that the value you have written down for the value calculated for
  811.       Why, Quit, and Echo are all identical, implying that if you jump to
  812.       this number, you will have access to all three files.
  813.          What this really means is that the FILE HEADER BLOCKS of these three
  814.       files are members of the same hash chain.
  815.  
  816.       7. Jump to the first file in the hash chain by hitting the j key.  I
  817.       cannot say exactly which FILE HEADER BLOCK you will be shown, since
  818.       that depends on in what order the files in the chain were created on
  819.       this disk.  Note that the value beside P-Go Parent =  is that of the
  820.       USER DIRECTORY BLOCK of the directory containing this file, namely the
  821.       c directory.
  822.  
  823.       8.  Note that the block address beside C-Go Hash Chain =  is non-zero.
  824.       At least, if the files Echo, Quit, and Why are in the c directory on
  825.       this disk, the value will be non-zero.  Otherwise, this demonstration
  826.       will not be successful.  To display the header of the next file or
  827.       directory in this hash chain, hit the c key (indicated by C-Go Hash
  828.       Chain).
  829.  
  830.       9.  Note that the value beside P-Go Parent hasn't changed.  This is
  831.       because all members of a hash chain always belong to the same
  832.       directory.  To traverse the hash chain and find the last FILE HEADER
  833.       BLOCK or USER DIRECTORY BLOCK in the chain, keep hitting the c key
  834.       until the value beside C-Go Hash Chain becomes zero.  When this
  835.       happens, further presses of the c key will merely cause the display
  836.       to flash, indicating you are at the end of the hash chain.
  837.  
  838.       10. Jump back to the ROOT BLOCK by hitting the r key.
  839.  
  840.         To find what an extension file looks like, we must look for a large
  841.       file... one where the amount of data is large enough that more pointers
  842.       are available in a FILE HEADER BLOCK's DATA BLOCK pointer table.  A
  843.       DATA BLOCK pointer table usually has 72 available entries.  Since each
  844.       BLOCK is 512 bytes long, we need a file that is over 72 x 512 = 36864
  845.       bytes long.  The Preferences file is about twice that length, so let's
  846.       take a look at it.
  847.  
  848.       11. Calculate the hash value for Preferences using the hash function.
  849.  
  850.       12. Jump to the FILE HEADER BLOCK for the Preferences file by hitting
  851.       the j key.  You will note that all the entries in the DATA BLOCK
  852.       pointer table in this FILE HEADER BLOCK are used-up.  You will find
  853.       the rest of the pointers required to point to the rest of the DATA
  854.       BLOCKS for this file in the file list.  The block number of the first
  855.       FILE LIST BLOCK in the file list is shown beside X-Go Extension.
  856.  
  857.       13. Hit the x key to jump to the first FILE LIST BLOCK.  Note that the
  858.       block number displayed beside P-Go Parent is the same as the block
  859.       number of the FILE HEADER BLOCK to which this FILE LIST BLOCK belongs.
  860.       Also note that the value beside X-Go Extension is now zero.  If the
  861.       required even more DATA BLOCKS, that is, if the file was longer than
  862.       about 73kbytes, the value beside X-Go Extension would point to the next
  863.       FILE LIST BLOCK in the file list.
  864.  
  865.         So, that pretty well wraps-up the tour.  We've seen all the data
  866.       structures used by AmigaDOS and have had a chance to modify a block.
  867.       There are a number of implications of AmigaDOS structure that this
  868.       document hasn't covered, but these things will become apparent as you
  869.       are given the opportunity to apply the disk editor.
  870.  
  871.         I hope the information forwarded by this document will help you solve
  872.       or at least understand problems that may occur from time to time when
  873.       storing things on AmigaDOS compatible devices.
  874.  
  875. A Trouble-shooting Example
  876. --------------------------
  877.         This information was recently invaluable to me as I discovered a
  878.       problem with my hard drive recently that could have blossomed into a
  879.       fairly major disaster.  A file was written on top of another file.
  880.  
  881.         I kept getting a read/write error when I tried to copy the
  882.       over-written file to another device.  So, I examined the hard drive
  883.       with Sectorama.  I used the hash function to locate which hash chain
  884.       the file was stored under, traversed the hash chain until I found the
  885.       file header block of the file in question.  I then traversed the list
  886.       of data blocks for the file by hitting the d key repeatedly.  The
  887.       list seemed to be intact since I was able to follow the list to its
  888.       last block.
  889.  
  890.         I then hit the h key to display the file header block again.  It
  891.       was the file header block of an entirely different file!  So, I jump
  892.       back to the root, jumped to the file I was originally investigating,
  893.       and again traversed the data block list while watching the value
  894.       beside H-Go Header for any changes.  About half-way through the file
  895.       the value changed.  I noted the block number of that data block,
  896.       hit the h key to jump to the wrong file header block again, and noted
  897.       that the block number of the erroneous data block was listed.  I went
  898.       back to the root block and back to the original file header block and
  899.       found that the same erroneous data block was listed here, too.
  900.  
  901.         I checked all the files on the hard disk, and found that only one
  902.       file was unreadable.  Thus, that file had been overwritten.  This
  903.       implied that somehow the bitmap of the disk was erroneous since the
  904.       data block used by the file was claimed by another file.  I had to
  905.       backup-up new files, format the hard drive to prevent further calamity,
  906.       and copy back all the files.  That cured the whole problem.
  907.  
  908.         I had a directory problem a while ago that I now know how to fix
  909.       recover from with a disk editor.  The directory of a device wrapped
  910.       around so that when I executed a list command, I got an endless
  911.       repetition of the same files, while other files on the disk would
  912.       never be listed.  When I listed the ignored files by naming them
  913.       directly, they would show up.  If I executed a dir command, the
  914.       storage device was searched and searched and searched until the
  915.       computer crashed.  I believe that is due to dir's method of collecting
  916.       all files in a directory for sorting until the end of the directory
  917.       is reached, which, in this case, it never did.
  918.  
  919.         Solving this is a matter of copying all files possible to another
  920.       device.  This means individually copying all the files since wildcards
  921.       cause a directory search which, in this case, would never end.  The
  922.       files you cannot see can be searched-out with Sectorama using wildcards
  923.       since Sectorama provides full-disk searches without consulting a
  924.       directory.  After finding and copying all your files to another device,
  925.       I'd recommend formatting the device to remove anything that might cause
  926.       a relapse of the problem.
  927.  
  928.       If you have any corrections, comments, or suggestions about the above
  929. document, please send them to me or tell me about them.  You can reach me at:
  930.  
  931.      //
  932.    \X/ Tesseract BBS
  933.        (306)757-5699
  934.        (24 hours, 8N1, 300 or 1200 baud)
  935.  
  936. address:  Dwayne Miller
  937.           770 Robinson Street
  938.           Regina, Saskatchewan, Canada  (Yup, way up there!)
  939.           S4T 2M1
  940.  
  941.   voice: (306)525-1652
  942.  
  943. P.S. Sectorama was written by David Joiner of MicroIllusions and is commonly
  944.      available, often named 'sec.arc' or 'sector.arc' or 'sectoram.arc' etc.
  945.  
  946.  
  947.       device.  This means individually copying all the files since wildcards
  948.       cause a directory search which, in this case, would never end.  The
  949.       files you cannot see can be searched-out with Sectorama using wildcards
  950.       since Sectorama provides full-disk searches without consulting a
  951.       directory.  After finding and copying all your files to another device,
  952.       I'd recommend formatting the device to remove anything that might cause
  953.       a relapse of the problem.
  954.  
  955.       If you have any corrections, comments, or suggestions about the above
  956. document, please send them to me or tell me about them.  You can reach me at:
  957.  
  958.      //
  959.    \X/ Tesseract BBS
  960.        (306)757-5699
  961.        (24 hours, 8N1, 300 or 1200 baud)
  962.  
  963. address:  Dwayne Miller
  964.           770 Robinson Street
  965.           Regina, Saskatchewan, Canada  (Yup, way up there!)
  966.           S4T 2M1
  967.  
  968.   voice: (306)525-1652
  969.  
  970. P.S. Sectorama was written by David Joiner of MicroIllusions and is commonly
  971.      available, often named 'sec.arc' or 'sector.arc' or 'sectoram.arc' etc.
  972.  
  973.